package com.ikun.admin.common.scheduled;


import com.ikun.common.constant.RedisConstant;
import com.ikun.common.manager.RedisManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;


/**
 * @ClassName ClearRedisTask
 * @Description: 定时清楚redis
 * @CreateDate: 2024/4/12 8:48
 */

@Component
public class ClearRedisTask {


    @Autowired
    private RedisManager redisManager;

    @Scheduled(cron = "25 30 2 * * *")
    public void run() {
        //定时清楚限流数据
        Set<String> limitKey = redisManager.keys(RedisConstant.LIMIT_SET_PREFIX);
        redisManager.remove(limitKey.toArray(new String[0]));
        //清楚黑名单数据
        Set<String> blackSet = redisManager.getSetVal(RedisConstant.BLACK_SET);
        redisManager.remove(blackSet.toArray(new String[0]));
    }
}
